﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.UI;

namespace HYRElectric.WirePlace
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class ChangeAngleDisCmd : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			this.m_app = commandData.Application.Application;
			this.m_uidoc = commandData.Application.ActiveUIDocument;
			this.m_doc = this.m_uidoc.Document;
			ICollection<Element> collection = new FilteredElementCollector(this.m_doc).OfClass(typeof(Wire)).ToElements();
			Transaction transaction = new Transaction(this.m_doc, "modify wire");
			try
			{
				transaction.Start();
				foreach (Element element in collection)
				{
					if (element != null && element is Wire)
					{
						ModelUpdater.InsertVertex(element as Wire, this.m_doc);
					}
				}
				transaction.Commit();
			}
			catch (Exception)
			{
				transaction.RollBack();
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private Application m_app;

		private UIDocument m_uidoc;

		private Document m_doc;
	}
}
